package com.taxi.driver.module.vo;

import com.alibaba.fastjson.JSON;
import com.taxi.driver.data.entity.HomeEntity;
import com.taxi.driver.data.entity.HomePageEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述：
 */
public class HomePageVO {

    private final static int MINUTE = 60; //单位秒
    private final static int HOUR = 60 * 60; //单位秒

    public static HomePageVO createFrom(HomePageEntity entity) {
        if (entity == null) return new HomePageVO();
        String strJson = JSON.toJSONString(entity);
        return JSON.parseObject(strJson, HomePageVO.class);
    }

    public static HomePageVO createFrom(HomeEntity entity) {
        HomePageVO vo = new HomePageVO();
        if (entity == null) return vo;
        vo.orderCount = entity.totalOrderDone;
        vo.orderIncome = entity.totalIncome;
        vo.onlineTime = entity.onWorkTime;
        vo.orderList = entity.orderList == null
                ? null
                : HomePageOrderVO.createFrom(entity.orderList);
        return vo;
    }

    public Integer orderCount; // 抢单数
    public Double orderIncome; // 收入
    public Long onlineTime; // 出车时长
    public HomePageOrderVO orderList;

    public List<HomePageOrderVO> getList() {
        ArrayList<HomePageOrderVO> list = new ArrayList<>();
        if (orderList != null) list.add(orderList);
        return list;
    }

//    public String uuid; // null,
//    public String driverUuid; // null,
//    public String onlineMileage; // null,
//    public String serviceMileage; // null,
//
//    public String workday; // null,
//    public String onWorkTime; // null,
//    public String offWorkTime; // null,
//
//    public String onserviceTime; // null,
//    public String onbanTime; // null,
//    public String complainCnt; // null,
//    public String createTime; // null

    public String getStrOnlineTime() {
        if (onlineTime == null || onlineTime < 1000) return "00:00";
        int sec = (int) (onlineTime / 1000); //秒数
        int hour = sec / HOUR; //小时
        int minute = sec % HOUR / MINUTE; //分钟
        StringBuilder str = new StringBuilder();
        if (hour < 10) str.append("0");
        str.append(hour);
        str.append(":");
        if (minute < 10) str.append("0");
        str.append(minute);
        return str.toString();
    }
}
